<%@ page contentType="text/html; charset=utf-8" language="java"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="thx" uri="/thx-tags"%>
<%@ taglib prefix="fun" uri="http://java.sun.com/jsp/jstl/functions"%>

<section class="content" id="filedList">
	<div class="row">
		<div class="col-md-12">
				<div class="box-body no-padding">
					<div class="row">
						<div class="col-sm-12">
							<table class="table table-bordered">
								<tr>
									<th>字段名称</th>
									<th>字段代码</th>
									<th>字段类型</th>
									<th>默认值</th>
									<th>长度</th>
									<th>是否显示</th>
									<th>是否输入</th>
									<th>显示顺序</th>
									<th width="20%">操作</th>
								</tr>
								<c:if test="${empty list}">
									<tr>
										<td colspan="9">暂无数据！</td>
									</tr>
								</c:if>
								<c:forEach items='${list}' var="field">
									<tr>
										<td>${field.fieldText}</td>
										<td>${field.fieldName}</td>
										<td>${field.fieldType}</td>
										<td>${field.defaultValue}</td>
										<td>${field.fieldLength}</td>
										<td>
											<c:if test="${field.isShow=='Y'}">是</c:if>
										</td>
										<td>
											<c:if test="${field.isNecessary=='Y'}">是</c:if>
										</td>
										<td>${field.seqenceNum}</td>
										<td>
											<button type="button" title="字段修改" data-toggle="tooltip"
												data-placement="bottom"
												open-url="workflow/field!input.action?id=${field.fieldId}&appId=${appId}"
												class="btn btn-default btn-sm btn-open-form">
												<i class="fa fa-edit"></i>
											</button>
											<button type="button" title="字段删除" data-toggle="tooltip"
												data-placement="bottom"
												do-url="workflow/field!delete.action?id=${field.fieldId}&appId=${appId}"
												confirm-msg="确定要删除吗？"
												class="btn btn-default btn-sm fieldList-delete">
												<i class="fa fa-trash"></i>
											</button>
									</tr>
								</c:forEach>
							</table>
						</div>
					</div>
				</div>
			<div class="handlePanel">
				<a title="新增字段" class="a-btn btn-open-form" 
					data-toggle="tooltip" data-placement="bottom"
					open-url="workflow/field!input.action?appId=${appId}"> 
					<span class="fa fa-plus"></span>
					<span class="text">新增</span>
				</a>
			</div>
		</div>
	</div>
</section>
<script>
	$(function() {
		list.init("#filedList");
		
		$.ajax({
			url : ctxPath+"/workflow/appConfig!getTabAuth.action",
			data : "appId="+'${appId}',
			type : 'post',
			success : function(msg) {
				msg = util.strToObj(msg);
				if(msg[0]=="1"){//字段管理
					$('a[href="#field-manage"]').parent("li").show();
				}else{
					$('a[href="#field-manage"]').parent("li").hide();
				}
				if(msg[1]=="1"){//表单模板
					$('a[href="#form-template"]').parent("li").show();
				}else{
					$('a[href="#form-template"]').parent("li").hide();
				}
				if(msg[2]=="1"){//字段读写性设置
					$('a[href="#field-auth"]').parent("li").show();
				}else{
					$('a[href="#field-auth"]').parent("li").hide();
				}
				if(msg[3]=="1"){//流程操作权限
					$('a[href="#flow-operate"]').parent("li").show();
				}else{
					$('a[href="#flow-operate"]').parent("li").hide();
				}
			},
			error : function() {
			}
	 	});
		$("#filedList .fieldList-delete").click(function(){
			var doUrl = $(this).attr("do-url");
			var loadUrl = $(this).attr("load-url");
			var container = $(this).attr("load-container");
			var confirmMsg = $(this).attr("confirm-msg");
			var title = $(this).attr("title");
			var winTitle = title ? title : $(this).attr("data-original-title");
			
			var callBack = function(params, modal) {
				$.ajax({
					url : ctxPath + "/" + params.doUrl,
					type : 'post',
					success : function(msg) {
						modal.modal('hide');
						msg = util.strToObj(msg);
						$("li[role='presentation'][class='active']").find("a").click();
						
						dialog.alert(msg.desc);
					}
				});
			};
	
			var params = {
				"doUrl" : doUrl,
				"loadUrl" : loadUrl,
				"container" : container
			};
			dialog.confirm(params, callBack, null, confirmMsg, title);
		});
	});
</script>